package com.kotiln.lgc.module_voice_setting

import android.widget.SeekBar
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.kotiln.lgc.lib_base.adapter.CommonAdapter
import com.kotiln.lgc.lib_base.adapter.CommonViewHolder
import com.kotiln.lgc.lib_base.base.BaseActivity
import com.kotiln.lgc.lib_base.helper.ARouterHelper
import com.kotiln.lgc.lib_voice.manager.VoiceManager
import kotlinx.android.synthetic.main.activity_voice_setting.*

/**
 *@fileName ConstellationActivity
 *@date2021/1/14  13:52
 *@author ConstellationActivity$
 *@describe TODO
 *@desc 语音设置
 */
@Route(path= ARouterHelper.PATH_VOICE_SETTING)
class Voice_Setting_Activity:BaseActivity() {

    private val mList:MutableList<String> = mutableListOf()

    private var mTtsPeopleIndex:Array<String>?=null

    override fun getLayoutId(): Int {
        return R.layout.activity_voice_setting
    }

    override fun getTitleText(): String {
        return getString(com.kotiln.lgc.lib_base.R.string.app_voice_setting_name)
    }

    override fun isShowBack(): Boolean {
        return true
    }

    override fun initView() {
        //默认值
        bar_voice_speed.progress=5
        bar_voice_volume.progress=5

        //设置最大值
        bar_voice_speed.max=15
        bar_voice_volume.max=15

        initPeopleData()

        initListener()

        initPeopleView()

        //测试按钮
        btn_test.setOnClickListener {
            VoiceManager.ttsStart("大家好,我是马东桑")
        }


    }

    //初始化recyclerView数据
    private fun initPeopleData() {
        val mTtsPeople:Array<String> = resources.getStringArray(R.array.TTSPeople)
        mTtsPeopleIndex= resources.getStringArray(R.array.TTSPeopleIndex)
        mTtsPeople.forEach {
            mList.add(it)
        }
    }

    //初始化发音人列表
    private fun initPeopleView() {
        rv_voice_people.layoutManager=LinearLayoutManager(this)
        //item分割线
        rv_voice_people.addItemDecoration(DividerItemDecoration(this,DividerItemDecoration.VERTICAL))
        rv_voice_people.adapter=CommonAdapter(mList,object:CommonAdapter.OnBindDataListener<String>{
            override fun onBindViewHolder( model: String,viewHolder: CommonViewHolder,
                type: Int, position: Int)
             {
                viewHolder.setText(R.id.mTvPeopleContent,model)
                 viewHolder.itemView.setOnClickListener {
                     mTtsPeopleIndex?.let {
                         VoiceManager.setPeople(it!![position])
                     }
                 }
             }

            override fun getLayoutId(type: Int): Int {
                return R.layout.layout_tts_people_list
            }

        })

    }

    //初始化监听
    private fun initListener() {
        //语速监听 拖动
        bar_voice_speed.setOnSeekBarChangeListener(object:SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                bar_voice_speed.progress=progress
                VoiceManager.setVoiceSpeed(progress.toString())
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }

        })

        //音量监听 拖动
        bar_voice_volume.setOnSeekBarChangeListener(object:SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
                bar_voice_volume.progress=progress
                VoiceManager.setVoiceVolume(progress.toString())
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
            }

        })
    }

    override fun initData() {
    }

    override fun destoryData() {
    }
}


